﻿using System.Data;
using System.Data.SqlClient;

namespace VMukti.DataAccess
{
    public class ClsBuddyReqDataService : ClsDataServiceBase
    {

        public ClsBuddyReqDataService() : base() { }

        ////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///	Creates a new DataService and specifies a transaction with
        ///	which to operate
        /// </summary>
        ////////////////////////////////////////////////////////////////////////
        public ClsBuddyReqDataService(IDbTransaction txn) : base(txn) { }

        public DataSet BuddyReq_GetAll()
        {            
            return ExecuteDataSet("Select * vMyBuddy;", CommandType.Text, null);
        }

        public DataSet BuddyReq_GetByID(int ID)
        {
            return ExecuteDataSet("spGBuddyRequest", CommandType.StoredProcedure, 
                CreateParameter("@pID", SqlDbType.BigInt, ID),
                CreateParameter("@pUserID", SqlDbType.BigInt, -1));
        }

        public DataSet BuddyReq_GetByUserID(int UserID)
        {
            return ExecuteDataSet("spGBuddyRequest", CommandType.StoredProcedure,
                CreateParameter("@pID", SqlDbType.BigInt, -1),
                CreateParameter("@pUserID", SqlDbType.BigInt, UserID));
        }

        public void BuddyReq_Save(ref int ID, int UserID, string DisplayName, int ReqUserID, ref int Result)
        {
            SqlCommand cmd;
            ExecuteNonQuery(out cmd, "spAEBuddyRequest",
                CreateParameter("@pID", SqlDbType.Int, ID, ParameterDirection.InputOutput),
                CreateParameter("@pUserID", SqlDbType.Int, UserID),
                CreateParameter("@pDisplayName", SqlDbType.VarChar, DisplayName, 50),
                CreateParameter("@pReqUserID", SqlDbType.Int, ReqUserID),
                CreateParameter("@pResult", SqlDbType.Int, Result, ParameterDirection.InputOutput));

            ID = int.Parse(cmd.Parameters["@pResult"].Value.ToString());
            Result = int.Parse(cmd.Parameters["@pResult"].Value.ToString());

            cmd.Dispose();
        }

        public void BuddyReq_Delete(int ID)
        {
            ExecuteNonQuery("spDBuddyRequest", CreateParameter("@pID", SqlDbType.Int, ID));
        }

    }
}
